<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends MY_Front_Controller {

	public function index($content_id = 0) {
	
		if($this->session->userdata('selected_country') === FALSE){
			$this->session->set_userdata(array('selected_country' => $this->config->item('def_country')));
		}
		
		if($this->session->userdata('selected_currency') === FALSE){
			$this->session->set_userdata(array('selected_currency' => $this->config->item('def_currency')));
		}
		
		$data['central_content'] = 'home_page_central_content';
		
		if ($content_id){
			$data['central_content'] .= '_subcategory_' . $content_id;
		}
		
		if (isset($_GET['affiliate']) && !empty($_GET['affiliate'])){
			$idAffiliate = base64_decode($_GET['affiliate']);
			$this->session->set_userdata(array('idAffiliate' => $idAffiliate));
		}
		
		/*$this->simpleloginsecure->create('zsolt@royalbijuterii.ro','admin#123');

		$this->load->model('category_model');
		$this->load->model('product_model');

		$product_sku = 'PD036W';
		$products = $this->product_model->get_list(array('where'=>$product_sku,'limit'=>2));*/

		$this->load->model('product_model');
		$this->load->model('category_model');
		
		$products_promo = $this->product_model->getAll(array('promotion' => 1, 'language_id' => $this->config->item('lang_obj')->id))->result();
		
		$data['products_promo'] = $products_promo;		
		$data['content'] 	= 'product/main';
		
			
		//$data['shapes'] = $this->product_model->getAll(array('field' => 'shape', 'group_by' => 'shape', 'order'=>'shape', 'language_id' => $this->config->item('lang_obj')->id))->result();
		
		$this->template->add_css('application/assets/js/jqueryPlugins/jCarousel/skins/tango/skin.css');
		$this->template->add_js('application/assets/js/jqueryPlugins/nivoSlider/jquery.nivo.slider.js');
		$this->template->add_css('application/assets/js/jqueryPlugins/nivoSlider/nivo-slider.css');
		$this->template->write('pageTitle', lang('home',false));
        $this->template->write_view ( 'content', 'front/main.php', $data );
        $this->template->render ();
        
       

	}
/*
	public function test_auth()
	{
		$this->load->library('SimpleLoginSecure');
		// create a new user
		//$this->simpleloginsecure->create('kisglaci@yahoo.com', '123qwe');

		// attempt to login
		if($this->simpleloginsecure->login('kisglaci@yahoo.com', '123qwe')) {
			echo "logged in";
		}
		else{
			echo "not oke login";
		}

		// check if logged in
		if($this->session->userdata('logged_in')) {
			// logged in
		}

		// logout
		$this->simpleloginsecure->logout();

		// delete by user ID
		//$this->simpleloginsecure->delete($user_id); 
	}*/

	public function product_details() 
	{
		$this->load->model('category_model');
		$menu = $this->category_model->get_menu_str();
		$this->data['menu'] = $menu;

		// ide irhatod a details oldalat ezt modosithatod
		$this->_view('product_details');
	}

	function get_country($language_id = 0){
			
		if (!$this->session->userdata('auto')){
			$this->load->model('country_model');
			$this->load->model('currency_model');
			$countries = $this->country_model->get_by_params(array('language_id' => $language_id))->result();
			if (count($countries)){
				$this->session->set_userdata(array('selected_country' => $countries[0]->id));
				
				if ($countries[0]->currency_id){
					$currency = $this->currency_model->get_by_id($countries[0]->currency_id);
					$this->session->set_userdata(array('selected_currency' => $currency->name));
				}
			}
		}
	}
	
	public function page($page = ''){
		if (strlen($page)){
			$this->template->write('pageTitle', lang($page,false));
			$this->template->write_view ( 'content', 'front/' . $page . '.php', array());
        	$this->template->render ();
		}
	}
	
	public function selectShippingCurrency($country, $currency) {
		$this->load->library('user_agent');
		$this->session->set_userdata(array('selected_country' => $country, 'selected_currency' => $currency, 'auto' => 1));
		 
		 redirect($this->agent->referrer());
	}
}